package com.nulldev.util.networking.npacket4.iprotocols.ncryptx;

import com.nulldev.util.security.encryptAPI.Encryptors.SystemEncryptors;

public enum CipherOption {

	/* nCryptX ciphers */

	RABBIT(1, CipherRating.NCRYPTX_READY),
	IDEA(9, CipherRating.NCRYPTX_READY),
	NACL_SHARED(10, CipherRating.NCRYPTX_READY),

	/* Generic Encryptors */

	ICE(2, CipherRating.GOOD),
	AES128(3, CipherRating.MEDIUM),
	AES128_CTR(4, CipherRating.GOOD),
	DES(5, CipherRating.BAD),
	XXTEA(6, CipherRating.BAD),
	RC4(7, CipherRating.VERY_BAD),
	SERPENT(8, CipherRating.MEDIUM),

	;

	private final short id;
	private final CipherRating rating;

	private CipherOption(final int f, final CipherRating rating) {
		this.id = (short) f;
		this.rating = rating;
	}

	public short id() {
		return this.id;
	}

	public CipherRating getRating() {
		return this.rating;
	}

	public SystemEncryptors asSystem() {
		switch (this) {
			case AES128:
				return SystemEncryptors.AES128;
			case AES128_CTR:
				return SystemEncryptors.AES128_COUNTER;
			case DES:
				return SystemEncryptors.DES;
			case IDEA:
				return SystemEncryptors.IDEA;
			case ICE:
				return SystemEncryptors.ICE;
			case NACL_SHARED:
				return SystemEncryptors.NaCl_Shared;
			case RABBIT:
				return SystemEncryptors.RABBIT;
			case RC4:
				return SystemEncryptors.RC4;
			case SERPENT:
				return SystemEncryptors.SERPENT;
			case XXTEA:
				return SystemEncryptors.XXTEA;
			default:
				throw new UnsupportedOperationException("Cannot convert '" + this + "' into a SystemEncryptor.");
		}
	}

	public static CipherOption get(final short s) {
		for (final CipherOption v : values())
			if (v.id == s)
				return v;
		throw new UnsupportedOperationException("Unknown method: " + s);
	}

	public static enum CipherRating {
		NCRYPTX_READY(5),
		GOOD(4),
		MEDIUM(3),
		BAD(2),
		VERY_BAD(1)

		;

		private final int rating;

		private CipherRating(final int rating) {
			this.rating = rating;
		}

		public int getIntRating() {
			return this.rating;
		}
	}
}
